package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserChangeBean;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.clientCenter.queryBean.UserChangeQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户变动情况初始化查询接口
 * 
 * @author 甄玉晴
 *
 */
public class UserInfoChgList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			@SuppressWarnings("rawtypes")
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
			UserChangeQueryBean bean = JsonUtils.objectToPojo(req.getData(), UserChangeQueryBean.class);
			UserInfoMapper mapper = factory.getMapper(UserInfoMapper.class);
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			List<UserChangeBean> cdList = new ArrayList<UserChangeBean>();
			//查询列表
			List<UserChangeBean> list = mapper.userChangeList(bean);
			List<UserChangeBean> quickList = mapper.quickUserChangeList(bean);
			
			if(list !=null && list.size() > 0)
				cdList.addAll(list);
			if(quickList !=null && quickList.size() > 0)
				cdList.addAll(quickList);

			info.setData(new PageInfo<>(cdList));
			return info;
		} catch (Exception e) {
			logger.error("用户变更信息查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
